package nuc.lizongze.backend.controller;


import nuc.lizongze.backend.service.BackendService;
import nuc.lizongze.pojo.TbItem;
import nuc.lizongze.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/backend/item")
public class BackendController {
    @Autowired
    private BackendService backendService;

    /**
     * 查询所有商品，页面接收到分页信息（成功、失败情况）
     * @param page
     * @param rows
     * @return
     */
    @RequestMapping("/selectTbItemAllByPage")
    public Result selectTbItemAllByPage(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "2") Integer rows){
        try {
            return backendService.selectTbItemAllByPage(page,rows);
        }catch (Exception e){
            e.printStackTrace();
        }
        return Result.build(500,"error");
    }
    /**
     * 添加商品
     */
    @RequestMapping("/insertTbItem")
    public Result insertTbItem(TbItem tbItem,String desc,String itemParamItem){
        try{
            return this.backendService.insertTbItem(tbItem, desc, itemParamItem);
        }catch (Exception e){
            e.printStackTrace();
        }
        return Result.build(500,"error");
    }
}
